package com.hui.xiao.xiaohui.ui;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/21.
 */
public class NotificationTest extends Activity {
    static final int NOTIFICATION_ID = 0x123;
    NotificationManager nm;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.notification);
        nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    }

    public void send(View view) {
        Intent intent = new Intent(NotificationTest.this, OtherActivity.class);
        PendingIntent pi = PendingIntent.getActivity(NotificationTest.this, 0, intent, 0);
        Notification notify = new Notification.Builder(this)
                .setAutoCancel(true)
                .setTicker("有新消息了")
                .setSmallIcon(R.drawable.bkch)
                .setContentTitle("你有一条新的消息")
                .setContentText("恭喜你, 你中奖了 ,五百万")
                .setVibrate(new long[]{0, 50, 100, 150})
                .setWhen(System.currentTimeMillis())
                .setContentIntent(pi)
                .build();
        nm.notify(NOTIFICATION_ID, notify);
    }

    public void del(View view) {
        nm.cancel(NOTIFICATION_ID);

    }
}
